import { CacheKeyEnum } from "@/enums/CacheKeyEnum";
import Cookies from "js-cookie";

/**
 * 设置Token
 * @param accessToken
 * @param refreshToken
 */
export function setToken(accessToken: string, refreshToken: string) {
  localStorage.setItem(
    CacheKeyEnum.ACCESS_TOKEN_KEY,
    CacheKeyEnum.TOKEN_TYPE_KEY + " " + accessToken
  );
  localStorage.setItem(
    CacheKeyEnum.REFRESH_TOKEN_KEY,
    CacheKeyEnum.TOKEN_TYPE_KEY + " " + refreshToken
  );
  // Cookies.set(CacheKeyEnum.ACCESS_TOKEN_KEY, CacheKeyEnum.TOKEN_TYPE_KEY + " " + accessToken);
  // Cookies.set(CacheKeyEnum.REFRESH_TOKEN_KEY, CacheKeyEnum.TOKEN_TYPE_KEY + " " + refreshToken);
}

/**
 * 设置Token
 * @param accessToken
 * @param refreshToken
 */
export function clearToken() {
  localStorage.removeItem(CacheKeyEnum.ACCESS_TOKEN_KEY);
  localStorage.removeItem(CacheKeyEnum.REFRESH_TOKEN_KEY);
  // Cookies.remove(CacheKeyEnum.ACCESS_TOKEN_KEY);
  // Cookies.remove(CacheKeyEnum.REFRESH_TOKEN_KEY);
}

/**
 * 获取AccessToken
 * @returns
 */
export function getAccessToken() {
  // return Cookies.get(CacheKeyEnum.ACCESS_TOKEN_KEY);
  return localStorage.getItem(CacheKeyEnum.ACCESS_TOKEN_KEY);
}

/**
 * 获取RefreshToken
 * @returns
 */
export function getRefreshToken() {
  // return Cookies.get(CacheKeyEnum.REFRESH_TOKEN_KEY);
  return localStorage.getItem(CacheKeyEnum.REFRESH_TOKEN_KEY);
}
